package com.ncf.jucai.accessmeter;

import lombok.extern.slf4j.Slf4j;

import java.util.Properties;

/**
 * 读配置
 * Created by lichengwen on 7/11/16.
 */
@Slf4j
class Config
{
    private static Properties config;

    static {
        try {
            String profile = System.getProperty("jucai.accessMeter.profile");
            String path = "/config.properties";
            if (profile != null && profile.length() > 0) {
                profile = profile.trim();
                path = "/config-" + profile + ".properties";
            }
            config = new Properties();
            log.info("loading config:" + path);
            config.load(Config.class.getResourceAsStream(path));
        } catch (Exception e) {
            log.error("load config failed", e);
            System.exit(1);
        }
    }

    static String get(String key) {
        return config.getProperty(key);
    }

    static String get(String key, String defaultValue) {
        String cnf = get(key);
        if (cnf == null || cnf.length() == 0) {
            return defaultValue;
        } else {
            return cnf;
        }
    }

}
